package com.tsxy.mall.controller.api;

import com.tsxy.mall.entity.APIResult;
import com.tsxy.mall.entity.Book;
import com.tsxy.mall.entity.Cart;
import com.tsxy.mall.entity.User;
import com.tsxy.mall.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/api/cart")
public class APICartController {
    @Autowired
    private CartService cartService;
    @GetMapping("/getAll")
    public List<Cart> getAllByUserId(HttpSession session){
        User user = (User) session.getAttribute("user");
        return cartService.getAll(user.getId());
    }

    @GetMapping("/update")
    public APIResult update(Integer id, Integer count){
        APIResult result = new APIResult();
        result.setData(cartService.update(id, count));
        result.setStatus("200");
        return result;
    }
}
